/* $Header: test_tbls.c,v 2.2 01/10/02 10:29:25 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  test_tbls.c                                           */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:  To define command tables for test/temporary        */
/*                  datacomm commands.                                 */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <error.h>
#include <p_wkfile.h>
#include <p_status.h>
#include <method.h>

#include <exception.h>
#include <err_handler.h>

#include <messages.h>

#include <flow.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/

   INT32 TP_Parm[3];

/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/

/********************* wrapper function prototypes *********************/

static INT32 mTestForException(void *parm, U_INT8 num);
static INT32 mGetExceptionNumber(void *parm, U_INT8 num);
static INT32 mGetExceptionType(void *parm, U_INT8 num);
static INT32 mGetExceptionRepeatable(void *parm, U_INT8 num);
static INT32 mGetExceptionDevCode(void *parm, U_INT8 num);
static INT32 mGetExceptionPopUpMsgPresent(void *parm, U_INT8 num);
static INT32 mGetExceptionStatusMsgPresent(void *parm, U_INT8 num);
static INT32 mGetExceptionGlpMsgPresent(void *parm, U_INT8 num);
static INT32 mGetExceptionTypeString(void *parm, U_INT8 num);
static INT32 mGetPneuDspData(void *parm, U_INT8 num);

static UI_ERR mSetTP_Parm(void *parm, INT32 setpt, U_INT8 num);
static UI_ERR mSetException(void *parm, INT32 setpt, U_INT8 num);
static UI_ERR mSetPneuDspData(void *parm, INT32 setpt, U_INT8 num);

static INT32  DummyGet(void *parm, U_INT8 num);
static UI_ERR DummyFunction(void *parm);
static UI_ERR DummySet(void *parm, INT32 setpt, U_INT8 num);


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

/********************* command table entries *********************/

/* Pneu Dsp Peek/Poke for Harry */

static const METHCMD_ENTRY mmTPPK[] =
{
        {DummyGet,        mSetTP_Parm,     0, METH_INT0},  /* Peek or Poke Mode */
        {DummyGet,        mSetTP_Parm,     1, METH_HEX},   /* Address */
        {mGetPneuDspData, mSetPneuDspData, 0, METH_HEX},   /* Value   */
};

static const METHCMD_ENTRY mmTPES[] =
{
        {mGetExceptionNumber,           mSetTP_Parm,   0, METH_INT0},
        {mTestForException,             mSetTP_Parm,   1, METH_INT0},
        {mGetExceptionType,             mSetException, 0, METH_INT0},
        {mGetExceptionRepeatable,       DummySet,      0, METH_INT0},
        {mGetExceptionDevCode,          DummySet,      0, METH_INT0},
        {mGetExceptionPopUpMsgPresent,  DummySet,      0, METH_INT0},
        {mGetExceptionStatusMsgPresent, DummySet,      0, METH_INT0},
        {mGetExceptionGlpMsgPresent,    DummySet,      0, METH_INT0},
        {mGetExceptionTypeString,       DummySet,      0, METH_STR},
};

/********************* command tables *********************/

const METHCMD mTPPK =
{
        MAXINDEX(mmTPPK, METHCMD_ENTRY),
        &mmTPPK[0],
        (void *)FRONT,
        DummyFunction,
        DummyFunction
};

const METHCMD mTPES =
{
        MAXINDEX(mmTPES, METHCMD_ENTRY),
        &mmTPES[0],
        (void *)FRONT,
        DummyFunction,
        DummyFunction
};

/********************* "get" wrapper functions *********************/

static INT32 mTestForException(void *parm, U_INT8 num)
{
   (void)parm;
   (void)num;
   return (INT32)TestForException( (EXCEPTION)TP_Parm[0] );
}

static INT32 mGetExceptionNumber(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      return (INT32)Exception_Info[ i ].exception_no;
   }
   return 0;
}

static INT32 mGetExceptionType(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      return (INT32)Exception_Info[ i ].exception_type;
   }
   return 0;
}

   const char sSCROLLING_TITLE[]   = "SCROLLING_TITLE";
   const char sREADINESS_0[]       = "READINESS_0";
   const char sMETHOD_WARNING_0[]  = "METHOD_WARNING_0";
   const char sWARNING_0[]         = "WARNING_0";
   const char sWARNING_1[]         = "WARNING_1";
   const char sSHUTDOWN_0[]        = "SHUTDOWN_0";
   const char sNON_FATAL_ERR_0[]   = "NON_FATAL_ERR_0";
   const char sNON_FATAL_ERR_1[]   = "NON_FATAL_ERR_1";
   const char sNON_FATAL_ERR_2[]   = "NON_FATAL_ERR_2";
   const char sNOT_KNOWN[]         = "UNKNOWN";

static INT32 mGetExceptionTypeString(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      switch ( Exception_Info[ i ].exception_type )
      {
         case SCROLLING_TITLE:  return (INT32)sSCROLLING_TITLE;
         case READINESS_0:      return (INT32)sREADINESS_0;
         case METHOD_WARNING_0: return (INT32)sMETHOD_WARNING_0;
         case WARNING_0:        return (INT32)sWARNING_0;
         case WARNING_1:        return (INT32)sWARNING_1;
         case SHUTDOWN_0:       return (INT32)sSHUTDOWN_0;
         case NON_FATAL_ERR_0:  return (INT32)sNON_FATAL_ERR_0;
         case NON_FATAL_ERR_1:  return (INT32)sNON_FATAL_ERR_1;
         case NON_FATAL_ERR_2:  return (INT32)sNON_FATAL_ERR_2;
         default:               return (INT32)sNOT_KNOWN;
      }
   }
   return (INT32)sNOT_KNOWN;
}
static INT32 mGetExceptionRepeatable(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      return (INT32)Exception_Info[ i ].repeatable;
   }
   return 0;
}

static INT32 mGetExceptionDevCode(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      return (INT32)Exception_Info[ i ].glp_dev_code;
   }
   return 0;
}

static INT32 mGetExceptionStatusMsgPresent(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      if ( Exception_Info[ i ].status_msg_no != NO_MSG ) return 1;
   }
   return 0;
}

static INT32 mGetExceptionGlpMsgPresent(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      if ( Exception_Info[ i ].glp_msg_no != NO_MSG ) return 1;
   }
   return 0;
}

static INT32 mGetExceptionPopUpMsgPresent(void *parm, U_INT8 num)
{
   INT16 i;

   (void)parm;
   (void)num;
   i = TP_Parm[0];

   if ( ValidExceptionIndex( (EXCEPTION)i ) )
   {
      if ( Exception_Info[ i ].msg_no != NO_MSG ) return 1;
   }
   return 0;
}

static INT32 DummyGet(void *parm, U_INT8 num)
{
   (void)parm;
   (void)num;

   return 0;
}

static UI_ERR DummyFunction(void *which)
{
        (void) which;
        return OK;
}

static UI_ERR DummySet(void *parm, INT32 setpt, U_INT8 num)
{
   (void) parm;
   (void) setpt;
   (void) num;
   return OK;
}

/********************* "set" wrapper functions *********************/

static UI_ERR mSetTP_Parm(void *parm, INT32 setpt, U_INT8 num)
{
        (void) parm;
        TP_Parm[num] =  setpt;
        return OK;
}

/********/
/* TPPK */
/********/

static INT32 mGetPneuDspData(void *parm, U_INT8 num)
{
   BIT8 result_code;

        (void) parm;
        (void) num;
        result_code = PcbPeek( TP_Parm[1], (U_INT32 *)&TP_Parm[2] );

        if ( result_code ) return TP_Parm[2];
        else return (INT32)( 0x80000000 );
}

static UI_ERR mSetPneuDspData(void *parm, INT32 setpt, U_INT8 num)
{
        (void) parm;
        (void) num;

        /* See if the address indicates that we need to modify  */
        /* the data.                                            */
        if ( TP_Parm[1] >= 0x3800 )
        {
           setpt = setpt << 8;
        }

        if ( PcbPoke(TP_Parm[1], setpt) ) return OK;
        else return NOT_ALLOWED;
}

/********/
/* TPES */
/********/

static UI_ERR mSetException(void *parm, INT32 setpt, U_INT8 num)
{
        (void)parm;
        (void)num;

        if ( ValidExceptionIndex( (EXCEPTION)TP_Parm[0] ) )
        {
           if (setpt >= 0)
           {
              SetNewException( (EXCEPTION)TP_Parm[0], TP_Parm[1], setpt );
              return OK;
           }
           else
           {
              ClearNewException( (EXCEPTION)TP_Parm[0] );
              return OK;
           }
        }
        else
        {
           return INVALID_PARAM;
        }
}

